<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>首页 - 光年(Light Year Admin)后台管理系统模板</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">

    <link href="css/style.min.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">


    <link rel="stylesheet" href="js/jconfirm/jquery-confirm.min.css">
    <!--时间选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
    <link href="js/bootstrap-validator/css/bootstrapValidator.css" rel="stylesheet">
</head>

<body data-theme="default">
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a href="admin/index.jsp"><img src="images/upt.png" title="LightYear" alt="LightYear" /></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item active"> <a href="admin/index.html"><i class="mdi mdi-home"></i> 后台首页</a> </li>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-palette"></i>游戏管理</a>
                            <ul class="nav nav-subnav">
                                <li> <a href="admin/GamingPlatform.html">游戏平台管理</a> </li>
                                <li> <a href="admin/Games.html">游戏管理</a> </li>
                                <li> <a href="admin/Characters.html">游戏人物管理</a> </li>


                            </ul>
                        </li>

                    </ul>
                </nav>


            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> </span>
                    </div>

                    <ul class="topbar-right">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">

                                <span><span id="user"></span> <span class="caret"></span></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">

                                <li> <a href="javascript:void(0)" id="Update"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>

                                <li class="divider"></li>
                                <li> <a href="javascript:void(0)" id="out"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->

                        <!--切换主题配色-->
                    </ul>

                </div>
            </nav>

        </header>
        <!--左侧导航-->

        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="toolbar-btn-action">
                                <button id="addBtn" onclick="showAdd()" type="button" class="btn btn-primary m-r-5" href="#!"><i class="mdi mdi-plus"></i> 新增</button>

                            </div>
                            <div class="card-body">

                                <div class="table-responsive" id="GamingPlatform-table">


                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">添加平台</h4>
            </div>
            <div class="modal-body">
                <form id="AddFrom" class="form-horizontal" action="lyear_forms_elements.html" method="post" onsubmit="return false;">
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="planameadd">平台名称</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="planameadd" name="planameadd" placeholder="请输入平台名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="plalocationadd">平台公司所属位置</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="plalocationadd" name="plalocationadd" placeholder="请输入平台公司所属位置">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addGamingPlatform()">确定</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >修改平台</h4>
            </div>
            <div class="modal-body">
                <form id="UpdateFrom" class="form-horizontal" action="lyear_forms_elements.html" method="post" onsubmit="return false;">
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="planameUpdate">平台名称</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="planameUpdate" name="planameUpdate" placeholder="请输入平台名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="plalocationUpdate">平台公司所属位置</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="plalocationUpdate" name="plalocationUpdate" placeholder="请输入平台公司所属位置">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updateGamingPlatform()">确定</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="dateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >修改密码</h4>
            </div>
            <div class="modal-body">
                <form id="dateFrom" class="form-horizontal" action="lyear_forms_elements.html" method="post" onsubmit="return false;">

                    <div class="form-group">
                        <label class="col-md-4 control-label" for="upasswordUpdate">当前密码</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="upasswordUpdate" name="upasswordUpdate" placeholder="请输入当前密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-4 control-label" for="dpasswoUpdate">请输入修改后的密码</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="dpasswoUpdate" name="dpasswoUpdate" placeholder="请输入修改后的密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-4 control-label" for="dpasswoagain">再次输入修改的密码</label>
                        <div class="col-md-7">
                            <input class="form-control" type="text" id="dpasswoagain" name="dpasswoagain" placeholder="请再次输入修改的密码">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updatePassword()">确定</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="js/Chart.js"></script>
<script  src="js/template-web.js"></script>
<!--对话框-->
<script src="js/jconfirm/jquery-confirm.min.js"></script>
<script src="js/bootstrap-notify.min.js"></script>

<script type="text/javascript" src="js/lightyear.js"></script>

<!--时间选择插件-->
<script src="js/bootstrap-datetimepicker/moment.min.js"></script>
<script src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
<!--日期选择插件-->
<script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<script src="js/echarts.js"></script>
<script type="text/javascript" src="js/bootstrap-validator/js/bootstrapValidator.js"></script>

<script type="text/html" id="all_GamingPlatform">
    <table class="table table-hover" >

        <tr>
            <th>id</th>
            <th>部门名称</th>
            <th>部门位置</th>
            <th>操作</th>
        </tr>


        {{each data}}
        <tr>
            <th scope="row">{{$value.plaid}}</th>
            <td>{{$value.planame}}</td>
            <td>{{$value.plalocation}}</td>
            <td>
                <button type="button" class="btn btn-info btn-xs" onclick="showUpdate('{{$value.plaid}}')">修改</button>
                <button type="button" class="btn btn-danger btn-xs" onclick="daleteById('{{$value.plaid}}')">删除</button>
            </td>
        </tr>
        {{/each}}


    </table>
</script>
<script type="text/javascript">
    $("#dateFrom").bootstrapValidator({
        feedbackIcons: {//这里是用来对应三种不同状态时，在输入框后面添加的图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{//哪些字段需要验证，和html中的输入框，下拉框等等表单name属性所对应。
            upasswordUpdate:{
                validators:{//从这里也可以容易的看出可以有多个验证信息
                    notEmpty:{//非空验证
                        message:"请输入密码！！！" //提示信息，当你不写这里时它会自动的调用自带的提示信息，默认是英文，可导入language下的中文JS文件
                    }

                }
            },
            dpasswoUpdate:{
                validators:{
                    notEmpty:{
                        message:"请输入修改后的密码！！！"
                    }
                }
            },
            dpasswoagain:{
                validators:{
                    notEmpty:{
                        message:"请输入修改后的密码！！！"
                    },
                    identical: {//用来判断制定的字段和当前字段一致与否
                        field: 'dpasswoUpdate',
                        message: "两次输入的密码不一致！！！"
                    }
                }
            }

        }
    });
    $("#Update").click(function showUpdate(){
        $("#dateModal").modal("show")
        //查询部门信息
        // $.ajax({
        //     url:"admin/DepartmentController?action=findById",
        //     type:'POST',
        //     data: {did:did},
        //     dataType:'JSON',
        //     success:function (resp){
        //         didupdate = resp.data.did
        //         if(resp.code==10000) {
        //             $("#dnameUpdate").val(resp.data.dname)
        //             $("#dlocationUpdate").val(resp.data.dlocation)
        //             $("#updateModal").modal("show")
        //         }else{
        //             lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
        //         }
        //     }
        // })

    })
    function updatePassword(){
        $("#dateFrom").data('bootstrapValidator').validate();//相当于触发一次所有的验证
        if($("#dateFrom").data('bootstrapValidator').isValid()){
            $.ajax({
                url:"adminup",
                dataType:'JSON',
                type:'POST',
                data:{password:$("#upasswordUpdate").val(),password1:$("#dpasswoUpdate").val()},
                success:function (resp){
                    if(resp.code==10000){
                        $("#dateModal").modal("hide")
                        //清空数据
                        //$("#UpdateFrom")[0].reset();
                        lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
                        //findAll();
                        setTimeout(function() {
                            // 在这里放置你想要延迟执行的代码
                            window.location.href="/login.html";
                        }, 1000)

                    }else{
                        lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                    }
                }
            })}
    }


    $("#out").click(function (){
        $.ajax({
            url:"loginout",
            type:"GET",
            dataType:"JSON",
            success:function (resp){
                window.location.href="/login.html";
            }
        })
    })



    $.ajax(
        {
            url:"admin/info",
            type:"GET",
            dataType:"JSON",
            success:function (resp){
                console.log(resp.data)
                $("#user").text(resp.data.username)
            }
        }
    )
    $("#UpdateFrom").bootstrapValidator({
        feedbackIcons: {//这里是用来对应三种不同状态时，在输入框后面添加的图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {//哪些字段需要验证，和html中的输入框，下拉框等等表单name属性所对应。
            planameUpdate: {
                validators: {//从这里也可以容易的看出可以有多个验证信息
                    notEmpty: {//非空验证
                        message: "请输入名称！！！" //提示信息，当你不写这里时它会自动的调用自带的提示信息，默认是英文，可导入language下的中文JS文件
                    },
                    // stringLength: {//长度限制（中文字符也算一个）
                    //     min: 4,
                    //     max: 16,
                    //     message: "用户名长度只能在4到16位之间！！！"
                    // }
                }
            },
            plalocationUpdate: {
                validators: {
                    notEmpty: {
                        message: "请输入游戏平台所属公司位置！！！"
                    }
                }
            }
        }})
    $("#AddFrom").bootstrapValidator({
        feedbackIcons: {//这里是用来对应三种不同状态时，在输入框后面添加的图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {//哪些字段需要验证，和html中的输入框，下拉框等等表单name属性所对应。
            planameadd: {
                validators: {//从这里也可以容易的看出可以有多个验证信息
                    notEmpty: {//非空验证
                        message: "请输入名称！！！" //提示信息，当你不写这里时它会自动的调用自带的提示信息，默认是英文，可导入language下的中文JS文件
                    },
                    // stringLength: {//长度限制（中文字符也算一个）
                    //     min: 4,
                    //     max: 16,
                    //     message: "用户名长度只能在4到16位之间！！！"
                    // }
                }
            },
            plalocationadd: {
                validators: {
                    notEmpty: {
                        message: "请输入游戏平台所属公司位置！！！"
                    }
                }
            }
        }})
    var plaidupdate = 0;
    function updateGamingPlatform(){
        $("#UpdateFrom").data('bootstrapValidator').validate();//相当于触发一次所有的验证
        if($("#UpdateFrom").data('bootstrapValidator').isValid()){
        $.ajax({
            url:"admin/GamingPlatformController",
            type:'PUT',
            data: JSON.stringify({planame:$("#planameUpdate").val(),plalocation:$("#plalocationUpdate").val(),plaid: plaidupdate  }),
            contentType:"application/json;charset=utf-8",
            dataType:'JSON',
            success:function (resp){
                if(resp.code==10000){
                    $("#updateModal").modal("hide")
                    //清空数据
                    $("#UpdateFrom")[0].reset();
                    lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
                    findAll();
                }else{
                    lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                }
            }
        })}
    }
    //修改模态框显示当前信息
    function showUpdate(plaid){
        //查询部门信息
        $.ajax({
            url:"admin/GamingPlatformController/" + plaid,
            type:'GET',
            data: {plaid:plaid},
            dataType:'JSON',
            success:function (resp){
                plaidupdate = resp.data.plaid
                if(resp.code==10000) {
                    $("#planameUpdate").val(resp.data.planame)
                    $("#plalocationUpdate").val(resp.data.plalocation)
                    $("#updateModal").modal("show")
                }else{
                    lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                }
            }
        })

    }
    //模态框确定按钮添加部门
    function addGamingPlatform(){
        $("#AddFrom").data('bootstrapValidator').validate();//相当于触发一次所有的验证
        if($("#AddFrom").data('bootstrapValidator').isValid()){
            console.log({planame: $("#planameadd").val(), plalocation: $("#plalocationadd").val()})
        $.ajax({
            url: "admin/GamingPlatformController",
            type: 'POST',
            data: JSON.stringify({planame: $("#planameadd").val(), plalocation: $("#plalocationadd").val()}),
            contentType:"application/json;charset=utf-8",
            dataType: 'JSON',
            success: function (resp) {
                if (resp.code == 10000) {
                    $("#addModal").modal("hide")
                    //清空数据
                    $("#AddFrom")[0].reset();
                    lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
                    findAll();
                } else {
                    lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                }
            }
          })}
    }
    //按钮弹出添加模态框
    function showAdd(){
        $("#addModal").modal("show")

    }

    //删除数据
    function daleteById(plaid){
        $.alert({
            title: '删除',
            content: '您确认要删除吗',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function(){

                        $.ajax({
                            url:"admin/GamingPlatformController/" + plaid,
                            type:'DELETE',
                            data: {plaid:plaid},
                            dataType:'JSON',
                            success:function (resp){
                                if(resp.code==10000){
                                    lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
                                    console.log("111111111")
                                    findAll();
                                }else{
                                    lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                                }
                            }
                        })
                    }
                },
                cancel: {
                    text: '取消'
                }
            }
        });

    }
    function findAll(){
        //发送ajax请求
        $.ajax({
            url:"admin/GamingPlatformController/findAll",
            type:'GET',
            dataType:'JSON',
            success:function (resp){
                if(resp.code==10000){
                    console.log(resp)
                    //渲染数据
                    let table = template('all_GamingPlatform', {data:resp.data});
                    //挂在
                    $("#GamingPlatform-table").html(table);

                }else{
                    lightyear.notify(resp.msg, 'danger', 1000, 'mdi mdi-emoticon-sad', 'top', 'center');
                }
            }
        });
    }

    // 页面加载时获取并渲染部门数据
    findAll();
</script>
</body>
</html>